package com.cdwm.mrp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdwm.mrp.common.tools.LayuiResponse;
import com.cdwm.mrp.domain.po.Host;
import com.cdwm.mrp.mapper.HostMapper;
import com.cdwm.mrp.service.HostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @version v1.0
 * @Author: lyw
 * @Date: 2021/8/19
 */
@Service
public class HostServiceImpl extends ServiceImpl<HostMapper, Host> implements HostService {

    @Autowired(required = false)
    private HostMapper hostMapper;

    @Override
    public LayuiResponse<?> getHostList(Host host, Integer page, Integer limit) {
        Page<Host> pager = new Page<>(page, limit);

        QueryWrapper<Host> queryWrapper = new QueryWrapper<>();

        queryWrapper.like(
                Objects.nonNull(host.getNetworkAddress())&& !Objects.equals("",host.getNetworkAddress()),
                "network_address",host.getNetworkAddress())
                .like(Objects.nonNull(host.getHostIP())&& !Objects.equals("",host.getHostIP()),
                        "host_ip",host.getHostIP());

        Page<Host> hostPage = hostMapper.selectPage(pager, queryWrapper);

        return LayuiResponse.ok(hostPage.getRecords(),hostPage.getTotal());
    }
}
